var $ = {
    ajax: function({
       url,
       type = 'get',
       data = {},
       async = true,
       success,
       error,
       complete=function(res){},
       dataType = 'json',
    }) {
        var xhr = new XMLHttpRequest()
        xhr.open(type, url, async)
        xhr.onreadystatechange = function () {
            if(xhr.readyState === 4) {
                if(xhr.status === 200) {
                    if(dataType == 'json') {
                        success(JSON.parse(xhr.responseText))
                    } else if(dataType == 'text') {
                        successs(xhr.responseText)
                    } else{
                        success(xhr.responseXML)
                    }
                }else{
                    console.error(xhr.status)
                }
                complete(xhr)
            }
        }
        if(type.toLowerCase() == 'post'){
            xhr.setRequestHeader('Content-type','application/x-www-form-urlencoded')
            xhr.send(data)
        }else{
            xhr.send()
        }
    } 
}